#import "AppDelegate.h"
#import "home/HomeController.h"
#import "play/PlayController.h"
#import "order/OrderController.h"
#import "mine/MineController.h"
#import "account/LoginController.h"
#import "RentManager.h"

@interface AppDelegate ()
@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    [self loadRentData];
    
    UITabBarController *tabBarController = [[UITabBarController alloc] init];

    UITabBarAppearance *tabBarAppearance = [[UITabBarAppearance alloc] init];

    tabBarAppearance.backgroundColor = [UIColor whiteColor];
    if (@available(iOS 13.0, *)) {
        tabBarController.tabBar.standardAppearance = tabBarAppearance;
        tabBarController.tabBar.scrollEdgeAppearance = tabBarAppearance;
    } else {
        tabBarController.tabBar.barTintColor = [UIColor whiteColor];
    }
    
    HomeController *homeVC = [[HomeController alloc] init];
    UINavigationController *homeNav = [[UINavigationController alloc] initWithRootViewController:homeVC];
    homeVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"首页"
                                                      image:[UIImage imageNamed:@"tab1"]
                                              selectedImage:[UIImage imageNamed:@"tab1—未选中"]];
    
    PlayController *playVC = [[PlayController alloc] init];
    UINavigationController *playNav = [[UINavigationController alloc] initWithRootViewController:playVC];
    playVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"玩法"
                                                      image:[UIImage imageNamed:@"tab2"]
                                              selectedImage:[UIImage imageNamed:@"tab2—未选中"]];
    
    OrderController *orderVC = [[OrderController alloc] init];
    UINavigationController *orderNav = [[UINavigationController alloc] initWithRootViewController:orderVC];
    orderVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"订单"
                                                       image:[UIImage imageNamed:@"tab3"]
                                               selectedImage:[UIImage imageNamed:@"tab3—未选中"]];
    
    MineController *mineVC = [[MineController alloc] init];
    UINavigationController *mineNav = [[UINavigationController alloc] initWithRootViewController:mineVC];
    mineVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我的"
                                                      image:[UIImage imageNamed:@"tab4"]
                                              selectedImage:[UIImage imageNamed:@"tab4—未选中"]];
    
    tabBarController.viewControllers = @[homeNav, playNav, orderNav, mineNav];
    self.tabBarController = tabBarController;
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    
    
    self.window.rootViewController = tabBarController;
    
    [self.window makeKeyAndVisible];
    
    return YES;
}

- (void)goToLogin {
    LoginController *loginVC = [[LoginController alloc] init];
    UINavigationController *loginNav = [[UINavigationController alloc] initWithRootViewController:loginVC];
    self.window.rootViewController = loginNav;
}

- (void)enterHome {
    self.tabBarController.selectedIndex = 0;
    self.window.rootViewController = self.tabBarController;
}

- (void)loadRentData {
    RentManager *manager = [RentManager sharedManager];
    [manager loadRentDataFromFile];

}

@end
